package com.itheima.health.dao;

import com.itheima.health.pojo.Menu;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import tk.mybatis.mapper.common.Mapper;

import java.util.List;

/**
 * @Author: liangWeiQUQ
 * @Description: 根据id查询相关菜单权限
 * @DateTime: 2021/3/11 9:23
 **/
public interface MenuMapper extends Mapper<Menu> {
    /**
     * @Author: 传闻中的梁大侠
     * @Date: 9:27 2021/3/11
     * @Parms [id]
     * @ReturnType: java.util.List<com.itheima.health.pojo.Menu>
     * @Description: 根据id查询一级菜单
     */
    @Select("SELECT\n" +
            "\tt3.id AS id,\n" +
            "\tt3.`name` AS title,\n" +
            "\tt3.icon AS icon,\n" +
            "\tt3.path AS path \n" +
            "FROM\n" +
            "\tt_role t1\n" +
            "\t\n" +
            "\tJOIN t_role_menu t2 ON t1.id = t2.role_id\n" +
            "\tJOIN t_menu t3 ON t2.menu_id = t3.id \n" +
            "WHERE\n" +
            "\tt1.id =#{id} AND t3.level = 1")
    List<Menu> getMenuList(@Param("id") Integer id);
    /**
       * @Author: 传闻中的梁大侠 
       * @Date: 9:29 2021/3/11
       * @Parms [id, id1]
       * @ReturnType: java.util.List<com.itheima.health.pojo.Menu>
       * @Description: 查询二级菜单
     */
    @Select("SELECT\n" +
            " t3.`name` AS title,\n" +
            " t3.path AS path,\n" +
            " t3.linkUrl AS linkUrl\n" +
            "FROM\n" +
            " t_role t1\n" +
            "JOIN\n" +
            " t_role_menu t2\n" +
            "ON\n" +
            " t1.id=t2.role_id\n" +
            "JOIN\n" +
            " t_menu t3\n" +
            "ON\n" +
            " t2.menu_id=t3.id\n" +
            "WHERE\n" +
            " t1.id=#{id} AND t3.parentMenuId=#{parentMenuId}\n")
    List<Menu> getMenuLists(@Param("id") Integer id, @Param("parentMenuId") Integer parentMenuId);
}
